package DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import POJO.Setor;

public class SetorDAO 
{
	Connection c;
	
	public SetorDAO()
	{
		GenericDao gDao = new GenericDao();
		c = gDao.getConnection();
	}
	
	public List<Setor> listaSetores() throws SQLException
	{
		List<Setor> listaSetores = new ArrayList<Setor>();
		String sql = "SELECT * FROM Setor ORDER BY nomeSetor";
		PreparedStatement ps = c.prepareStatement(sql);
		ResultSet rs = ps.executeQuery();
		
		while(rs.next())
		{
			Setor set = new Setor();
			set.setCodSetor(rs.getInt("codSetor"));
			set.setNomeSetor(rs.getString("nomeSetor"));
			
			listaSetores.add(set);
		}
		rs.close();
		ps.close();
		
		return listaSetores;
	}
}
